﻿@{
    ViewBag.Title = "提现记录";
    ViewBag.PathToBtn = "/Withdrawals/Create";
    ViewBag.TextBtn = "添加";
    Layout = "~/Views/Shared/_Layout.cshtml";
    @model  Matrix.MaKaYunShang.Model.McCashWithdrawApplication
}
@section css{
    <style type="text/css">
        .nav-tabs li {
            cursor: pointer;
        }
        .table hr {
            margin: 5px 0;
            border: dashed 1px #aaa;
        }

        .dataTables_length {
            display: none;
        }

        .dataTables_filter {
            display: none;
        }
    </style>
}
<!-- /.row -->
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                <form method="get">
                    店铺：
                    <input type="text" data-target='#TransferShopModal' data-toggle='modal' class="form-control input-sm" placeholder="店铺名称" style="width: 150px;display: inline-block" id="shopName" />
                    <input type="text" id="ShopId" name="ShopId"  style=" display:none"/>
                    <input type="reset" value="清空条件" class="btn btn-info" style="margin-left: 10px;" />
                    <a class="btn btn-primary pull-right" id="btnSearch">查询</a>
                </form>
            </div>
        </div>
    </div>


<div class="col-lg-12">
    <div class="panel panel-default">
        <div class="panel-heading">
            提现记录
        </div>
        <!-- /.panel-heading -->
        <div class="panel-body">
            <ul class="nav nav-tabs">
                <li>
                    <a data-toggle="tab" tag="-1">全部</a>
                </li>
                <li>
                    <a data-toggle="tab" tag="1">处理成功</a>
                </li>
                <li>
                    <a data-toggle="tab" tag="0">待处理</a>
                </li>
                <li>
                    <a data-toggle="tab" tag="2">处理失败</a>
                </li>

                <input type="hidden" id="HidDealStatus" value="-1" />
            </ul>
            <div class="dataTable_wrapper">
                <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                    <thead>
                        <tr>
                            <th>申请时间</th>
                            <th>银行名称</th>
                            <th>银行账号</th>
                            <th>开户行</th>
                            <th>银行卡账户名称</th>
                            <th>店铺名称</th>
                            <th>提现金额</th>
                            <th>备注</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
            <!-- /.table-responsive -->
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div><!-- /.row -->


<div class="modal fade" id="TransferShopModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="max-width: 500px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">查询店铺（<font color="red">仅显示已激活的店铺</font>）</h4>
            </div>
            <div class="modal-body">
                <div style="margin-bottom: 5px;">
                    <input type="text" class="form-control" placeholder="店铺名称" style="width: 409px;display: inline-block" id="shopKeyWords" />
                    <a class="btn btn-primary" onclick="searchShops();">查询</a>
                </div>
                <div class="table-responsive table-bordered" style="max-height: 250px;">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>店铺名称</th>
                                <th style="text-align: center">操作</th>
                            </tr>
                        </thead>
                        <tbody id="shopsData"></tbody>
                    </table>
                    <input type="hidden" id="hidOrderId" />
                </div>
            </div>
        </div>
    </div>
</div>
@section javascript{
    <script src="/Content/admin/dist/js/pagingHelper.js"> </script>
    <script type="text/javascript">
        var dataParams = {};
        var serverProcessPath = "/Withdrawals/Listing";
        var showColumns = [
            { data: "ApplyTimeStr" },
            { data: "BankName" },
            { data: "BankAccount" },
            { data: "BankOfDeposit" },
            { data: "BankAccountName" },
            { data: "ShopName" },
            { data: "CashValue" },
            { data: "Remark" },
            { data: "DealStatusStr" },
            { data: "Action" }
        ];
        pagingHelper.Paging(serverProcessPath, dataParams, showColumns);


        $(function () {
            $("#btnAssign").click(function () {
                $.post("@Url.Action("Assign")", "orderId=" + $("#hidOrderId").val() + "&deliveryId=" + $("#Delivery").val(), function (data) {
                    if (data.Status) {
                        $("#assignModal").modal("hide");
                        alertify.success(data.Message);
                        reloadOrder();
                    } else {
                        alertify.error(data.Message);
                    }
                });
            });

            $(".nav-tabs li a").click(function () {
                $("#HidDealStatus").val($(this).attr("tag"));
                reloadOrder();
            });

            $(".nav-tabs li a[tag='@(ViewBag.OrderStatus)']").parent().addClass("active").siblings().removeClass("active");

            $("#btnSearch").click(function () {
                reloadOrder();
            });

            searchShops();

        });

        function reloadOrder() {
            pagingHelper.reloadWithDiffPath("@Url.Action("Listing")" + "?DealStatus=" + $("#HidDealStatus").val() + "&ShopId=" + $("#ShopId").val());
        }

        function Withdrawals() {
            var amount = $("#CashWithdrawalAmount").html();
            if (amount < 1) {
                alertify.error("暂无提现额度,无法操作!");
            }
            location.href = "/Withdrawals/WithdrawOperation";
        }

        function Operation(id, type) {

            if (confirm("确定操作吗？")) {

                $.post("@Url.Action("Operation")", { Id: id, Type: type }, function (data) {
                    if (data.Status) {
                        alertify.success(data.Message);
                        location.reload();
                    } else {
                        alertify.error(data.Message);
                    }
                });
            }
        }

        function searchShops() {
            $("#shopsData").html("");
            $("#ShopId").val("");
            $("#shopName").val("");
            $.post("@Url.Action("GetShopList","GfcStat")", "keyWords=" + encodeURIComponent($("#shopKeyWords").val()), function (data) {
                if (data.Status) {
                    for (var i = 0; i < data.Data.length; i++) {
                        var orderName = "'" + data.Data[i].Name + "'";
                        $("#shopsData").append("<tr><td>" + data.Data[i].Name + "</td><td align='center'><a class='btn btn-info' onclick=\"selectShop(" + data.Data[i].Id + "," + orderName.toString() + ");\">选择</a></td></tr>");
                    }
                } else {
                    alertify.alert(data.Message);
                }
            });
        }
        function selectShop(shopId, name) {
            $("#ShopId").val(shopId);
            $("#shopName").val(name);
            $("#consumerNameDiv").show();
            $("#TransferShopModal").modal("hide");
        }
    </script>
}